#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define N 800005
#define getback(x) ((x)^lstans)
int head[N],nxt[N],ver[N],tot,fth[N];
void add(int x,int y){
	ver[++tot]=y;
	nxt[tot]=head[x];head[x]=tot;
}
int dp[N],dp2[N],mx[N];
signed main(){
	freopen("forest.in","r",stdin);
	freopen("forest.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int id,n;cin>>id>>n;int lstans=0;
	for(int i=2;i<=n;i++){
		int x;cin>>x;x=getback(x);
		add(i,x);add(x,i);fth[i]=x;
		vector<int> v;int p=i;
		dp[i]=mx[i]=1;
		while(p!=1){
			p=fth[p];v.push_back(p);
		}
		for(int j=0;j<v.size();j++){
			int x=v[j],mx1=0,mx2=0,mx3=0,mxv=0;
			for(int k=head[x];k;k=nxt[k]){
				int y=ver[k];
				if(y==fth[x])	continue;
				mxv=max(mxv,dp2[y]);mx[x]=max(mx[x],mx[y]);dp2[x]=max(dp2[x],dp2[y]);
				if(dp[y]>mx1){
					mx3=mx2;mx2=mx1;mx1=dp[y];
				}else if(dp[y]>mx2){
					mx3=mx2;mx2=dp[y];
				}else if(dp[y]>mx3){
					mx3=dp[y];
				}
			}
			lstans=max(lstans,mx1+mx2+max(0,mxv-1));
			dp2[x]=max(dp2[x],mx2);mx[x]=max(mx[x],mx1+mx2);dp[x]=mx1+1;
			for(int k=head[x];k;k=nxt[k]){
				int y=ver[k];
				if(y==fth[x])	continue;
				lstans=max(lstans,mx[y]+max(0,((mx1==dp[y])?mx2-1:mx1-1)));
			}
		}
		cout<<lstans<<"\n";
	}
	return 0;
}

